//
//  UILabel+XZWObject.m
//  LinkUsSNS
//
//  Created by apple on 16/9/7.
//  Copyright © 2016年 apple. All rights reserved.
//

#import "UILabel+XZWObject.h"
#define COLOR_NEW_RED [UIColor colorWithRed:201/255.0f green:69/255.0f blue:40/255.0f alpha:0.8]
#define COLOR_NEW_GRAY [UIColor colorWithRed:242.0/255.0f green:242.0/255.0f blue:242.0/255.0f alpha:1]

@implementation UILabel (XZWObject)
+ (NSMutableAttributedString *)addAttributedStringWithStr:(NSString *)str AndRange:(NSRange)range{
    NSMutableAttributedString *AttributedStr = [[NSMutableAttributedString alloc]initWithString:str];
    [AttributedStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:18.0] range:range];//字体大小
    [AttributedStr addAttribute:NSLigatureAttributeName value:@(1) range:range];//连体字
    [AttributedStr addAttribute:NSForegroundColorAttributeName value:[UIColor whiteColor] range:range];//字体颜色
    NSShadow *shadow = [[NSShadow alloc]init];
    shadow.shadowOffset = CGSizeMake(2, 2);
    shadow.shadowColor = COLOR_NEW_RED;
    shadow.shadowBlurRadius = 1;
    [AttributedStr addAttribute:NSShadowAttributeName value:shadow range:range];// 阴影
    return AttributedStr;
}
-(CGSize)messageBodyLabelwith:(float)labelwidth andLabelheight:(float)labelheight{
    CGSize size = [self.text boundingRectWithSize:CGSizeMake(labelwidth, labelheight) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:self.font} context:nil].size;
    return size;
}
+(CGSize)messageBodyText:(NSString *)text andSyFontofSize:(float)fontsize andLabelwith:(float)labelwidth andLabelheight:(float)labelheight{
    CGSize size = [text boundingRectWithSize:CGSizeMake(labelwidth, labelheight) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontsize]} context:nil].size;
    return size;
}
+(CGSize)messageBodyText:(NSString *)text andBoldSystemFontOfSize:(float)fontsize andLabelwith:(float)labelwidth andLabelheight:(float)labelheight{
    CGSize size = [text boundingRectWithSize:CGSizeMake(labelwidth, labelheight) options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName:[UIFont boldSystemFontOfSize:fontsize]} context:nil].size;
    return size;
}
+(CGSize)sizeWithText:(NSString *)text andFont:(UIFont *)font andMaxSize:(CGSize)maxSize{
    NSDictionary *attr = @{NSFontAttributeName: font};
    return [text boundingRectWithSize:maxSize options:NSStringDrawingTruncatesLastVisibleLine | NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:attr context:nil].size ;
}
+(UILabel *)addLabelWithAlignment:(NSTextAlignment)alignment andFont:(UIFont *)font andAddToView:(UIView *)view{
    UILabel *LB = [[UILabel alloc]init];
    LB.backgroundColor = [UIColor clearColor];
    LB.textColor = [UIColor whiteColor];
    LB.adjustsFontSizeToFitWidth = true;
    LB.numberOfLines = 1;
    LB.textAlignment = alignment;
    LB.font = font;
    [view addSubview:LB];
    return LB;
}
+(UILabel *)addLabelWithFrame:(CGRect)frame andTitle:(NSString *)title andAlignment:(NSTextAlignment)alignment andFont:(UIFont *)font andAddToView:(UIView *)view{
    UILabel *LB = [[UILabel alloc]initWithFrame:frame];
    LB.backgroundColor = [UIColor clearColor];
    if([title isEqualToString:@">"]) LB.textColor = COLOR_NEW_GRAY; else
    LB.textColor = [UIColor blackColor];
    LB.adjustsFontSizeToFitWidth = true;
    LB.numberOfLines = 1;
    LB.lineBreakMode = NSLineBreakByWordWrapping;
    LB.textAlignment = alignment;
    LB.font = font;
    LB.text = title;
    [view addSubview:LB];
    return LB;
}
+(UILabel *)addLabelLineWithFrame:(CGRect)frame andBackColor:(UIColor *)color andAddToView:(UIView *)view{
    UILabel *LB = [[UILabel alloc]initWithFrame:frame];
    LB.backgroundColor = color;
    [view addSubview:LB];
    return LB;
}




@end
